<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="180px">
      <el-form-item label="微信 APP ID" prop="wxAppId">
        <el-input v-model="form.wxAppId" placeholder="请输入微信 APP ID" />
      </el-form-item>
      <el-form-item label="微信 APP SECRET" prop="wxAppSecret">
        <el-input v-model="form.wxAppSecret" placeholder="请输入微信 APP SECRET" />
      </el-form-item>
      <el-form-item label="微信消息推送id" prop="wxTemplateId">
        <el-input v-model="form.wxTemplateId" placeholder="请输入微信消息推送id" />
      </el-form-item>
      <el-form-item label="微信消息推送反馈url" prop="wxTemplateUrl">
        <el-input v-model="form.wxTemplateUrl" placeholder="请输入微信消息推送反馈url" />
      </el-form-item>
      <el-form-item label="微信告警推送id" prop="wxAlertTemplateId">
        <el-input v-model="form.wxAlertTemplateId" placeholder="请输入微信告警推送id" />
      </el-form-item>
      <el-form-item label="微信告警推送反馈url" prop="wxAlertTemplateUrl">
        <el-input v-model="form.wxAlertTemplateUrl" placeholder="请输入微信告警推送反馈url" />
      </el-form-item>
      <el-form-item label="微信商户id" prop="wxPayMacId">
        <el-input v-model="form.wxPayMacId" placeholder="请输入微信商户id" />
      </el-form-item>
      <el-form-item label="微信支付key" prop="wxPayKey">
        <el-input v-model="form.wxPayKey" placeholder="请输入微信支付key" />
      </el-form-item>
      <el-form-item label="微信支付回调url" prop="wxPayNotifyUrl">
        <el-input v-model="form.wxPayNotifyUrl"  placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="微信商户支付证书" prop="wxPayCertStr">
        <el-input v-model="form.wxPayCertStr" type="textarea" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="支付手续费" prop="feeRatio">
        <el-input v-model="form.feeRatio" placeholder="请输入支付手续费" />
      </el-form-item>
      <el-form-item label="分账比例" prop="splitRatio">
        <el-input v-model="form.splitRatio" placeholder="请输入分账比例" />
      </el-form-item>
      <el-form-item label="公众号名称" prop="publicName">
        <el-input v-model="form.publicName" placeholder="请输入公众号名称" />
      </el-form-item>
      <el-form-item label="二维码图片" prop="publicQr">
        <image-upload v-model="form.publicQr"/>
      </el-form-item>
      <el-form-item label="系统地址" prop="feeRatio">
        <el-input v-model="form.baseUrl" placeholder="系统地址" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { listSystem_info, getSystem_info, delSystem_info, addSystem_info, updateSystem_info } from "@/api/system/system_info";

export default {
  name: "System_info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 平台设置表格数据
      system_infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      getSystem_info(1).then(response => {
        this.form = response.data;
      });
    },
    /** 查询平台设置列表 */
    getList() {
      this.loading = true;
      listSystem_info(this.queryParams).then(response => {
        this.system_infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        systemInfoId: null,
        wxAppId: null,
        wxAppSecret: null,
        wxTemplateId: null,
        wxTemplateUrl: null,
        wxAlertTemplateId: null,
        wxAlertTemplateUrl: null,
        wxPayMacId: null,
        wxPayKey: null,
        wxPayCertStr: null,
        wxPayNotifyUrl: null,
        feeRatio: null,
        splitRatio: null,
        publicName: null,
        publicQr: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        baseUrl: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.systemInfoId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加平台设置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const systemInfoId = row.systemInfoId || this.ids
      getSystem_info(systemInfoId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改平台设置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.systemInfoId != null) {
            updateSystem_info(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              // this.open = false;
              this.initData();
            });
          } else {
            addSystem_info(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              // this.open = false;
              this.initData();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const systemInfoIds = row.systemInfoId || this.ids;
      this.$modal.confirm('是否确认删除平台设置编号为"' + systemInfoIds + '"的数据项？').then(function() {
        return delSystem_info(systemInfoIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/system_info/export', {
        ...this.queryParams
      }, `system_info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
